package com.fisherman.config;

import com.fisherman.bean.Person;
import com.fisherman.service.BookService;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.FilterType;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;

/**
 * User: fisherman
 * Date: 2020/5/17 16:13
 * <p>
 * 注解形式
 * <p>
 * 配置类 == 配置文件
 * 一个是以java类的形式一个是xml形式
 */
@Configuration  //告诉spring这是一个配置类
@ComponentScan(value = "com.fisherman", includeFilters = {
        @ComponentScan.Filter(type = FilterType.ANNOTATION, classes = {Controller.class}), //指定排除规则  例子去掉了Controller Service
        @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, classes = {BookService.class}), //FilterType.ASSIGNABLE_TYPE,按照给定的类型
        @ComponentScan.Filter(type = FilterType.CUSTOM, classes = {MyTypeFilter.class}), //FilterType.CUSTOM,自定义规则
}, useDefaultFilters = false)  //注解加再扫描包  value:指定要扫描的包
//excludeFilters = Filter[]，指定扫描的时候按照什么规则排除那些组件
//includeFilters = Filter[].指定扫描时候只需要包含那些组件
//FilterType.ANNOTATION 按照注解方式
//FilterType.ASSIGNABLE_TYPE,按照给定的类型
//FilterType.ASPECTJ,使用ASPECTJ表达式
//FilterType.REGEX,正则表达式
//FilterType.CUSTOM,自定义规则
public class MainConfig {

    //注册组件
    @Bean("person")  //给容器一个Bean；类型为返回的类型，id默认是用方法名作为id  这里把id设置成person
    public Person person() {
        return new Person("fisherman", 23);
    }

}
